package com.hnust.controller.paper.paperManagement;

import com.hnust.domain.*;
import com.hnust.fx.FXMLController;
import com.hnust.service.TestPaperService;
import com.hnust.store.DataStore;
import com.hnust.store.PaperListDataStore;
import com.hnust.util.PaperDataModel;
import com.jfoenix.controls.JFXButton;
import javafx.collections.FXCollections;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.*;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.HBox;
import javafx.stage.Modality;
import javafx.stage.Stage;
import lombok.SneakyThrows;
import org.springframework.beans.factory.annotation.Autowired;
//时间选择器
import java.net.URL;
import java.time.LocalDate;
import java.util.List;
import java.util.ResourceBundle;

import javafx.scene.layout.VBox;
import javafx.scene.control.Pagination;

@FXMLController
public class PaperCorrectController implements Initializable {

    public static PaperDataModel model = new PaperDataModel();
    public static String paperId ; //从PaperList传来的试卷ID
    @Autowired
    private TestPaperService testPaperService; //对应的service层
    @Autowired
    private DataStore dataStore;
    @Autowired
    private PaperListDataStore paperListDataStore;

    @FXML
    public Button generatePaper;
    @FXML
    public Button autoPaper;
    @FXML
    public ScrollPane container;
    @FXML
    public AnchorPane contain;

    //考试名称
    @FXML
    public Label headTitle;

    //时间选择器
    @FXML
    public DatePicker testTimeStart;
    public DatePicker testTimeEnd;

    //考试创建人
    @FXML
    public Label creatPerson;

    //创建时间
    @FXML
    public Label creatTime;

    //按钮
    @FXML
    public JFXButton addQuestion;
    @FXML
    public JFXButton importDocument;
    @FXML
    public JFXButton manuallyAdd;
    @FXML
    public JFXButton correctScore;
    @FXML
    public JFXButton deleteQuestion;
    @FXML
    public JFXButton serveModify;
    @FXML
    public JFXButton prePage1;
    @FXML
    public JFXButton nextPage1;
    @FXML
    public JFXButton prePage2;
    @FXML
    public JFXButton nextPage2;
    @FXML
    public JFXButton prePage3;
    @FXML
    public JFXButton nextPage3;
    @FXML
    public JFXButton prePage4;
    @FXML
    public JFXButton nextPage4;
    @FXML
    public JFXButton comprehensiveQuestion;
    @FXML
    public JFXButton essayQuestion;
    @FXML
    public JFXButton completion;
    @FXML
    public JFXButton choiceQuestion;
    @FXML
    public JFXButton downLoad;
    @FXML
    public JFXButton upLoad;
    @FXML
    public JFXButton cancel;

    //多选框
    @FXML
    public CheckBox check1;
    @FXML
    public CheckBox check2;
    @FXML
    public CheckBox check3;
    @FXML
    public CheckBox check4;
    @FXML
    public CheckBox choiceCheck;
    @FXML
    public CheckBox judgeCheck1;
    @FXML
    public CheckBox judgeCheck2;
    @FXML
    public CheckBox judgeCheck3;
    @FXML
    public CheckBox judgeCheck4;
    @FXML
    public CheckBox judgeCheck5;
    @FXML
    public CheckBox judgeCheck6;
    @FXML
    public CheckBox gapCheck1;
    @FXML
    public CheckBox gapCheck2;
    @FXML
    public CheckBox gapCheck3;
    @FXML
    public CheckBox gapCheck4;
    @FXML
    public CheckBox gapCheck5;
    @FXML
    public CheckBox essayCheck;

    //题目框
    @FXML
    public VBox questions;
    @FXML
    public VBox question1;
    @FXML
    public VBox question2;
    @FXML
    public VBox question3;
    @FXML
    public VBox question4;

    //选择题样式框
    @FXML
    public VBox choice;
    @FXML
    public Label choiceEasy;
    @FXML
    public Label choiceNormal;
    @FXML
    public Label choiceDifficult;
    @FXML
    public Label choiceNumber;
    @FXML
    public Label choiceQuestionText;
    @FXML
    public Label choiceScore;
    @FXML
    public Label aChoice;
    @FXML
    public Label bChoice;
    @FXML
    public Label cChoice;
    @FXML
    public Label dChoice;

    //判断题样式框
    @FXML
    public VBox judge;
    @FXML
    public HBox remove1;
    @FXML
    public HBox remove2;
    @FXML
    public HBox remove3;
    @FXML
    public HBox remove4;
    @FXML
    public HBox remove5;
    @FXML
    public HBox remove6;
    @FXML
    public HBox remove7;
    @FXML
    public HBox remove8;
    @FXML
    public HBox remove9;
    @FXML
    public HBox remove10;
    @FXML
    public HBox remove11;
    @FXML
    public HBox remove12;
    @FXML
    public Label judgeEasy;
    @FXML
    public Label judgeNormal;
    @FXML
    public Label judgeDifficult;
    @FXML
    public Label judgeNumber1;
    @FXML
    public Label judgeNumber2;
    @FXML
    public Label judgeNumber3;
    @FXML
    public Label judgeNumber4;
    @FXML
    public Label judgeNumber5;
    @FXML
    public Label judgeNumber6;
    @FXML
    public Label judgeQuestionText1;
    @FXML
    public Label judgeQuestionText2;
    @FXML
    public Label judgeQuestionText3;
    @FXML
    public Label judgeQuestionText4;
    @FXML
    public Label judgeQuestionText5;
    @FXML
    public Label judgeQuestionText6;
    @FXML
    public Label judgeScore1;
    @FXML
    public Label judgeScore2;
    @FXML
    public Label judgeScore3;
    @FXML
    public Label judgeScore4;
    @FXML
    public Label judgeScore5;
    @FXML
    public Label judgeScore6;

    //填空题样式框
    @FXML
    public VBox gap;
    @FXML
    public HBox gapRemove1;
    @FXML
    public HBox gapRemove2;
    @FXML
    public HBox gapRemove3;
    @FXML
    public HBox gapRemove4;
    @FXML
    public HBox gapRemove5;
    @FXML
    public HBox gapRemove6;
    @FXML
    public HBox gapRemove7;
    @FXML
    public HBox gapRemove8;
    @FXML
    public HBox gapRemove9;
    @FXML
    public HBox gapRemove10;
    @FXML
    public Label gapEasy;
    @FXML
    public Label gapNormal;
    @FXML
    public Label gapDifficult;
    @FXML
    public Label gapNumber1;
    @FXML
    public Label gapNumber2;
    @FXML
    public Label gapNumber3;
    @FXML
    public Label gapNumber4;
    @FXML
    public Label gapNumber5;
    @FXML
    public Label gapQuestionText1;
    @FXML
    public Label gapQuestionText2;
    @FXML
    public Label gapQuestionText3;
    @FXML
    public Label gapQuestionText4;
    @FXML
    public Label gapQuestionText5;
    @FXML
    public Label gapScore1;
    @FXML
    public Label gapScore2;
    @FXML
    public Label gapScore3;
    @FXML
    public Label gapScore4;
    @FXML
    public Label gapScore5;

    //简答题样式框
    @FXML
    public VBox essay;
    @FXML
    public Label essayEasy;
    @FXML
    public Label essayNormal;
    @FXML
    public Label essayDifficult;
    @FXML
    public Label essayNumber;
    @FXML
    public Label essayQuestionText;
    @FXML
    public Label essayScore;

    //试卷信息统计
    @FXML
    public AnchorPane message;
    @FXML
    public Label totalQuestions;
    @FXML
    public Label totalScores;
    @FXML
    public Label easy;
    @FXML
    public Label normal;
    @FXML
    public Label difficult;
    @FXML
    public Label choices;
    @FXML
    public Label judges;
    @FXML
    public Label gaps;
    @FXML
    public Label essays;

    //题库添加
    @FXML
    public VBox add;

    //手动添加
    public VBox myAdd;

    //填空题按钮
    public VBox addChoiceQuestion;
    //选择题按钮
    public VBox addCompletion;
    //简答题按钮
    public VBox addEssayQuestion;
    //综合题按钮
    public VBox addComprehensiveQuestion;

    //文档导入
    @FXML
    public VBox myImport;
    //文档说明
    @FXML
    public Label label1;
    public Label label2;
    public Label label3;
    //标题
    @FXML
    public Label importD;


    static int i = 0; //渲染的选择题题目题号
    static int choiceLength; //选择题题目数
    static int choiceScores; //选择题分数
    static List<ChoiceTestQuestions> choiceQuestions;//选择题题目
    static int j = 0; //渲染的判断题题目题号
    static int judgeLength; //判断题题目数
    static int judgeScores; //判断题分数
    static List<JudgeTestQuestions> judgeQuestions;//tian题题目
    static int k = 0; //渲染的填空题题目题号
    static int gapLength; //填空题题目数
    static int gapScores; //填空题分数
    static List<GapTestQuestions> gapQuestions;//填空题题目
    static int m = 0; //渲染的简答题题目题号
    static int essayLength; //简答题题目数
    static int essayScores; //简答题分数
    static List<EssayTestQuestions> essayQuestions;//简答题题目
    @SneakyThrows
    @Override
    public void initialize(URL location, ResourceBundle resources) {
        paperId=model.getText();
        model.textProperty().addListener((obs, oldText, newText) -> {
            paperId=newText;
        });
        System.out.println("initialize  paperId:"+paperId);
        //设置按钮样式
        addQuestion.setStyle("-fx-cursor: hand;-fx-text-fill: #fff");
        importDocument.setStyle("-fx-cursor: hand;-fx-text-fill: #fff");
        manuallyAdd.setStyle("-fx-cursor: hand");
        correctScore.setStyle("-fx-cursor: hand;-fx-text-fill: #fff");
        deleteQuestion.setStyle("-fx-cursor: hand;-fx-text-fill: #fff");
        serveModify.setStyle("-fx-cursor: hand;-fx-text-fill: #fff");
        choiceQuestion.setStyle("-fx-cursor: hand;-fx-text-fill: #fff");
        completion.setStyle("-fx-cursor: hand;-fx-text-fill: #fff");
        essayQuestion.setStyle("-fx-cursor: hand;-fx-text-fill: #fff");
        comprehensiveQuestion.setStyle("-fx-cursor: hand;-fx-text-fill: #fff");
        downLoad.setStyle("-fx-pref-width: 140px;-fx-cursor: hand;-fx-text-fill: #fff");
        upLoad.setStyle("-fx-cursor: hand;-fx-text-fill: #fff");
        cancel.setStyle("-fx-cursor: hand");
        prePage1.setStyle("-fx-cursor: hand");
        nextPage1.setStyle("-fx-cursor: hand;-fx-text-fill: #fff");
        prePage2.setStyle("-fx-cursor: hand");
        nextPage2.setStyle("-fx-cursor: hand;-fx-text-fill: #fff");
        prePage3.setStyle("-fx-cursor: hand");
        nextPage3.setStyle("-fx-cursor: hand;-fx-text-fill: #fff");
        prePage4.setStyle("-fx-cursor: hand");
        nextPage4.setStyle("-fx-cursor: hand;-fx-text-fill: #fff");

        //获得考试信息
//        System.out.println("geTest前  paperId:"+paperId);
        Result<TestMessage> paper = testPaperService.getTest(paperId);

        //获得考试题目
        //选择题
        Result<List<ChoiceTestQuestions>> choiceQuestion1 = testPaperService.getChoiceQuestions(paperId);
        choiceQuestions = choiceQuestion1.getData();
//        System.out.println("paper："+paper);
        System.out.println("选择题："+choiceQuestion1.toString());
        choiceLength = choiceQuestions.size();
        System.out.println("选择题size："+choiceLength);
        int[] choiceLevel = choiceLevel(choiceQuestions);
        prePage1.setDisable(true);//设置上一页按钮不可用
        nextPage1.setDisable(choiceLength == 1);
        //判断题
        Result<List<JudgeTestQuestions>> judgeQuestioncopy = testPaperService.getJudgeQuestions(paperId);
        System.out.println("判断："+judgeQuestioncopy);
        judgeQuestions = judgeQuestioncopy.getData();
        judgeLength = judgeQuestions.size();
        int[] judgeLevel = judgeLevel(judgeQuestions);
        prePage2.setDisable(true);
        if(judgeLength>6)
            nextPage2.setDisable(false);
        else
            nextPage2.setDisable(true);
        //填空题
        Result<List<GapTestQuestions>> gapQuestioncopy = testPaperService.getGapQuestions(paperId);
        System.out.println("填空："+gapQuestioncopy);
        gapQuestions = gapQuestioncopy.getData();
        gapLength = gapQuestions.size();
        int[] gapLevel = gapLevel(gapQuestions);
        prePage3.setDisable(true);
        if(judgeLength>5)
            nextPage3.setDisable(false);
        else
            nextPage3.setDisable(true);
        //简答题
        Result<List<EssayTestQuestions>> essayQuestioncopy = testPaperService.getEssayQuestions(paperId);
        System.out.println("简答："+essayQuestioncopy);
        essayQuestions = essayQuestioncopy.getData();
        essayLength = essayQuestions.size();
        int[] essayLevel = essayLevel(essayQuestions);
        prePage4.setDisable(true);//设置上一页按钮不可用
        nextPage4.setDisable(essayLength == 1);


        //初始化主页题目
        //选择题
        if(choiceLength == 0){
            choice.getChildren().removeAll();
        }
        else{
            ChoiceTestQuestions choiceQuestion = choiceQuestions.get(i);
            choiceNumber.setText(Integer.toString(i+1));
            choiceQuestionText.setText(choiceQuestion.getQuestionText());
            choiceScore.setText(choiceQuestion.getScore());
            aChoice.setText(choiceQuestion.getaChoice());
            bChoice.setText(choiceQuestion.getbChoice());
            cChoice.setText(choiceQuestion.getcChoice());
            dChoice.setText(choiceQuestion.getdChoice());
        }
        //判断题
        if(j<judgeLength){
            JudgeTestQuestions judgeQuestion1 = judgeQuestions.get(j);
            judgeNumber1.setText(Integer.toString(j+1));
            judgeQuestionText1.setText(judgeQuestion1.getContent());
            judgeScore1.setText(judgeQuestion1.getScore());
        }
        else{
            judge.getChildren().remove(remove1);
            judge.getChildren().remove(remove2);
        }
        if(j+1<judgeLength){
            JudgeTestQuestions judgeQuestion2 = judgeQuestions.get(j+1);
            judgeNumber2.setText(Integer.toString(j+2));
            judgeQuestionText2.setText(judgeQuestion2.getContent());
            judgeScore2.setText(judgeQuestion2.getScore());
        }
        else{
            judge.getChildren().remove(remove3);
            judge.getChildren().remove(remove4);
        }
        if(j+2<judgeLength){
            JudgeTestQuestions judgeQuestion3 = judgeQuestions.get(j+2);
            judgeNumber3.setText(Integer.toString(j+3));
            judgeQuestionText3.setText(judgeQuestion3.getContent());
            judgeScore3.setText(judgeQuestion3.getScore());
        }
        else{
            judge.getChildren().remove(remove5);
            judge.getChildren().remove(remove6);
        }
        if(j+3<judgeLength){
            JudgeTestQuestions judgeQuestion4 = judgeQuestions.get(j+3);
            judgeNumber4.setText(Integer.toString(j+4));
            judgeQuestionText4.setText(judgeQuestion4.getContent());
            judgeScore4.setText(judgeQuestion4.getScore());
        }
        else{
            judge.getChildren().remove(remove7);
            judge.getChildren().remove(remove8);
        }
        if(j+4<judgeLength){
            JudgeTestQuestions judgeQuestion5 = judgeQuestions.get(j+4);
            judgeNumber5.setText(Integer.toString(j+5));
            judgeQuestionText5.setText(judgeQuestion5.getContent());
            judgeScore5.setText(judgeQuestion5.getScore());
        }
        else{
            judge.getChildren().remove(remove9);
            judge.getChildren().remove(remove10);
        }
        if(j+5<judgeLength){
            JudgeTestQuestions judgeQuestion6 = judgeQuestions.get(j+5);
            judgeNumber6.setText(Integer.toString(j+6));
            judgeQuestionText6.setText(judgeQuestion6.getContent());
            judgeScore6.setText(judgeQuestion6.getScore());
        }
        else{
            judge.getChildren().remove(remove11);
            judge.getChildren().remove(remove12);
        }
        //填空题
        if(k<gapLength){
            GapTestQuestions gapQuestion1 = gapQuestions.get(k);
            gapNumber1.setText(Integer.toString(k+1));
            gapQuestionText1.setText(gapQuestion1.getContent());
            gapScore1.setText(gapQuestion1.getScore());
        }
        else{
            gap.getChildren().remove(gapRemove1);
            gap.getChildren().remove(gapRemove2);
        }
        if(k+1<gapLength){
            GapTestQuestions gapQuestion2 = gapQuestions.get(k+1);
            gapNumber2.setText(Integer.toString(k+2));
            gapQuestionText2.setText(gapQuestion2.getContent());
            gapScore2.setText(gapQuestion2.getScore());
        }
        else{
            gap.getChildren().remove(gapRemove3);
            gap.getChildren().remove(gapRemove4);
        }
        if(k+2<gapLength){
            GapTestQuestions gapQuestion3 = gapQuestions.get(k+2);
            gapNumber3.setText(Integer.toString(k+3));
            gapQuestionText3.setText(gapQuestion3.getContent());
            gapScore3.setText(gapQuestion3.getScore());
        }
        else{
            gap.getChildren().remove(gapRemove5);
            gap.getChildren().remove(gapRemove6);
        }
        if(k+3<gapLength){
            GapTestQuestions gapQuestion4 = gapQuestions.get(k+3);
            gapNumber4.setText(Integer.toString(k+4));
            gapQuestionText4.setText(gapQuestion4.getContent());
            gapScore4.setText(gapQuestion4.getScore());
        }
        else{
            gap.getChildren().remove(gapRemove7);
            gap.getChildren().remove(gapRemove8);
        }
        if(k+4<gapLength){
            GapTestQuestions gapQuestion5 = gapQuestions.get(k+4);
            gapNumber5.setText(Integer.toString(k+5));
            gapQuestionText5.setText(gapQuestion5.getContent());
            gapScore5.setText(gapQuestion5.getScore());
        }
        else{
            gap.getChildren().remove(gapRemove9);
            gap.getChildren().remove(gapRemove10);
        }
        //简答题
        if(essayLength == 0){
            essay.getChildren().removeAll();
        }
        else{
            EssayTestQuestions essayQuestion = essayQuestions.get(i);
            essayNumber.setText(Integer.toString(i+1));
            essayQuestionText.setText(essayQuestion.getContent());
            essayScore.setText(essayQuestion.getScore());
        }

        //难易题目
        //选择题
        choiceEasy.setText(Integer.toString(choiceLevel[0]));
        choiceNormal.setText(Integer.toString(choiceLevel[1]));
        choiceDifficult.setText(Integer.toString(choiceLevel[2]));
        //判断题
        judgeEasy.setText(Integer.toString(judgeLevel[0]));
        judgeNormal.setText(Integer.toString(judgeLevel[1]));
        judgeDifficult.setText(Integer.toString(judgeLevel[2]));
        //填空题
        gapEasy.setText(Integer.toString(gapLevel[0]));
        gapNormal.setText(Integer.toString(gapLevel[1]));
        gapDifficult.setText(Integer.toString(gapLevel[2]));
        //简答题
        essayEasy.setText(Integer.toString(essayLevel[0]));
        essayNormal.setText(Integer.toString(essayLevel[1]));
        essayDifficult.setText(Integer.toString(essayLevel[2]));

        //试卷信息统计
        easy.setText(Integer.toString(choiceLevel[0]+judgeLevel[0]+gapLevel[0]+essayLevel[0]));
        normal.setText(Integer.toString(choiceLevel[1]+judgeLevel[1]+gapLevel[1]+essayLevel[1]));
        difficult.setText(Integer.toString(choiceLevel[2]+judgeLevel[2]+gapLevel[2]+essayLevel[2]));
        totalScores.setText(Integer.toString(totalScore(choiceQuestions,judgeQuestions,gapQuestions,essayQuestions)));
        totalQuestions.setText(Integer.toString(choiceLength+judgeLength+gapLength+essayLength));
        choices.setText(Integer.toString(choiceLength));
        judges.setText(Integer.toString(judgeLength));
        gaps.setText(Integer.toString(gapLength));
        essays.setText(Integer.toString(essayLength));

        //考试名称
        headTitle.setText(paper.getData().getTestName());//获取并设置考试名称

        //时间选择器
        testTimeStart.setValue(LocalDate.now()); //获取当前时间
        testTimeEnd.setValue(testTimeStart.getValue());

        //考试创建人
        creatPerson.setText(paper.getData().getName());//获取并设置创建人

        //创建时间
        creatTime.setText(paper.getData().getCreateTime());//获取并设置创建时间

        //题目选择框
        //设置Label可自动换行
        choiceQuestionText.setWrapText(true);
        aChoice.setWrapText(true);
        bChoice.setWrapText(true);
        cChoice.setWrapText(true);
        dChoice.setWrapText(true);

        judgeQuestionText1.setWrapText(true);
        judgeQuestionText2.setWrapText(true);
        judgeQuestionText3.setWrapText(true);
        judgeQuestionText4.setWrapText(true);
        judgeQuestionText5.setWrapText(true);
        judgeQuestionText6.setWrapText(true);

        gapQuestionText1.setWrapText(true);
        gapQuestionText2.setWrapText(true);
        gapQuestionText3.setWrapText(true);
        gapQuestionText4.setWrapText(true);
        gapQuestionText5.setWrapText(true);

        essayQuestionText.setWrapText(true);

        //初始化题库添加框
        addQuestionBox();

        //初始化 隐藏
        add.setVisible(false);
        add.setManaged(false);
        myAdd.setVisible(false);
        myAdd.setManaged(false);
        myImport.setVisible(false);
        myImport.setManaged(false);

        //文档导入说明
        importD.setText("文档导入");
        label1.setText("1，本系统支持导入的题型");
        label2.setText("单选题，多选题，不定项选择题，填空题，判断题，问答题，理解题（一个大标题下有多个小问题），排序题，匹配题，完型填空题");
        label3.setText("2，导入题目的word文档必须按照模板要求来进行填写");
    }

    public static void setText(String text) {
        model.setText(text);
    }

    //按钮功能实现
    //题库添加
    static Boolean question = true;
    public void AddQuestion(ActionEvent actionEvent) {
        //控制模块隐藏显示
        question = !question;
        message.setVisible(question);
        questions.setVisible(question);
        myAdd.setVisible(false);
        myImport.setVisible(false);

        message.setManaged(question);
        questions.setManaged(question);
        myAdd.setManaged(false);
        myImport.setManaged(false);

        add.setVisible(!question);
        add.setManaged(!question);

        cansee = true;
        visibility = true;
    }
    //题库添加框
    public void addQuestionBox(){
        //设置Box位置、样式
        add.setLayoutX(30);
        add.setLayoutY(300);
        VBox all = new VBox();
        all.setStyle("-fx-border-style: solid; -fx-border-color: #d1d1d9; -fx-min-width: 1530px");
        add.getChildren().add(all);

        //课程、章节、题型
        HBox header1 = new HBox();
        header1.setPadding(new Insets(20,0,0,30));
        header1.setAlignment(Pos.CENTER_LEFT);
        header1.setSpacing(30);
        all.getChildren().add(header1);

        HBox course = new HBox();
        HBox chapter = new HBox();
        HBox type = new HBox();
        header1.getChildren().add(course);
        header1.getChildren().add(chapter);
        header1.getChildren().add(type);

        //设置课程选择框
        Label course1 = new Label();
        ChoiceBox course2 = new ChoiceBox();
        course1.setText("所属课程：");
        course2.setItems(FXCollections.observableArrayList(
                "操作系统","通信原理","数字系统设计","高等数学","线性代数"));
        course2.setStyle("-fx-background-color: white;-fx-border-color: #4ca3f8;-fx-border-radius: 5px");
        course.getChildren().add(course1);
        course.getChildren().add(course2);

        //设置章节选择框
        Label chapter1 = new Label();
        ChoiceBox chapter2 = new ChoiceBox();
        chapter1.setText("所属章节：");
        chapter2.setItems(FXCollections.observableArrayList(
                "全选","第一章"));
        chapter2.setStyle("-fx-background-color: white;-fx-border-color: #4ca3f8;-fx-border-radius: 5px");
        chapter.getChildren().add(chapter1);
        chapter.getChildren().add(chapter2);

        //设置题型选择框
        Label type1 = new Label();
        ChoiceBox type2 = new ChoiceBox();
        type1.setText("所属题型：");
        type2.setItems(FXCollections.observableArrayList(
                "全选","第一章"));
        type2.setStyle("-fx-background-color: white;-fx-border-color: #4ca3f8;-fx-border-radius: 5px");
        type.getChildren().add(type1);
        type.getChildren().add(type2);

        //添加、搜索
        HBox header2 = new HBox();
        header2.setPadding(new Insets(30,0,20,30));
        header2.setAlignment(Pos.CENTER_LEFT);
        header2.setSpacing(30);
        all.getChildren().add(header2);

        HBox addCancel = new HBox(20);
        HBox searchRestart = new HBox(20);
        searchRestart.setPadding(new Insets(5,10,5,700));
        header2.getChildren().add(addCancel);
        header2.getChildren().add(searchRestart);

        //添加、取消按钮
        JFXButton sure = new JFXButton();
        JFXButton cancel = new JFXButton();
        sure.setText("确定添加");
        sure.setStyle("-fx-font-weight: bold;" +
                "    -fx-text-alignment: center;" +
                "    -fx-cursor: hand;" +
                "    -fx-border-color: transparent;" +
                "    -fx-border-width: 1px;" +
                "    -fx-border-style: solid;" +
                "    -fx-background-insets: 0, 0, -1, 0;" +
                "    -fx-padding: 6px 12px 6px 12px;" +
                "    -fx-font-size: 15px;" +
                "    -fx-border-radius: 7px;" +
                "    -fx-background-radius: 7px;" +
                "    -fx-pref-width: 100px;" +
                "    -fx-pref-height: 40px;" +
                "    -fx-text-fill: #fff;" +
                "    -fx-fill: #fff;" +
                "    -fx-background-color: #0084ff;" +
                "    -fx-border-color: #4ca3f8;");
        cancel.setText("取消添加");
        cancel.setStyle("-fx-font-weight: bold;" +
                "    -fx-text-alignment: center;" +
                "    -fx-cursor: hand;" +
                "    -fx-border-color: transparent;" +
                "    -fx-border-width: 1px;" +
                "    -fx-border-style: solid;" +
                "    -fx-background-insets: 0, 0, -1, 0;" +
                "    -fx-padding: 6px 12px 6px 12px;" +
                "    -fx-font-size: 15px;" +
                "    -fx-border-radius: 7px;" +
                "    -fx-background-radius: 7px;" +
                "    -fx-pref-width: 100px;" +
                "    -fx-pref-height: 40px;" +
                "    -fx-text-fill: #444444;" +
                "    -fx-fill: #fff;" +
                "    -fx-background-color: #EAEAFA;" +
                "    -fx-border-color: #f5eeee;");
        addCancel.getChildren().add(sure);
        addCancel.getChildren().add(cancel);

        //题目搜索、重置
        Label search = new Label();
        TextField searchText = new TextField();
        searchText.setStyle("-fx-background-color: white;-fx-border-color: #4ca3f8;-fx-border-radius: 5px");
        search.setText("题目搜索：");
        searchRestart.getChildren().add(search);
        searchRestart.getChildren().add(searchText);

        JFXButton searchBtn = new JFXButton();
        JFXButton restartBtn = new JFXButton();
        searchBtn.setText("搜索");
        searchBtn.setStyle("-fx-font-weight: bold;" +
                "    -fx-text-alignment: center;" +
                "    -fx-cursor: hand;" +
                "    -fx-border-color: transparent;" +
                "    -fx-border-width: 1px;" +
                "    -fx-border-style: solid;" +
                "    -fx-background-insets: 0, 0, -1, 0;" +
                "    -fx-padding: 6px 12px 6px 12px;" +
                "    -fx-font-size: 15px;" +
                "    -fx-border-radius: 7px;" +
                "    -fx-background-radius: 7px;" +
                "    -fx-pref-height: 40px;" +
                "    -fx-text-fill: #fff;" +
                "    -fx-fill: #fff;" +
                "    -fx-background-color: #0084ff;" +
                "    -fx-border-color: #4ca3f8;");
        restartBtn.setText("重置");
        restartBtn.setStyle("-fx-font-weight: bold;" +
                "    -fx-text-alignment: center;" +
                "    -fx-cursor: hand;" +
                "    -fx-border-color: transparent;" +
                "    -fx-border-width: 1px;" +
                "    -fx-border-style: solid;" +
                "    -fx-background-insets: 0, 0, -1, 0;" +
                "    -fx-padding: 6px 12px 6px 12px;" +
                "    -fx-font-size: 15px;" +
                "    -fx-border-radius: 7px;" +
                "    -fx-background-radius: 7px;" +
                "    -fx-pref-height: 40px;" +
                "    -fx-text-fill: #444444;" +
                "    -fx-fill: #fff;" +
                "    -fx-background-color: #EAEAFA;" +
                "    -fx-border-color: #f5eeee;");
        searchRestart.getChildren().add(searchBtn);
        searchRestart.getChildren().add(restartBtn);

        //分页
        Pagination pagination = new Pagination(10, 0); //新建分页控件
        pagination.setPageFactory((Integer pageIndex) -> createPage(pageIndex));

        all.getChildren().add(pagination);
    }

    //分页
    //设置一页几个item
    public int itemsPerPage() {
        return 3;
    }
    //创建分页界面
    public VBox createPage(int pageIndex) {
        VBox box = new VBox(10);
        int page = pageIndex * itemsPerPage();
        for (int i = page; i < page + itemsPerPage(); i++) {
            VBox element = new VBox();

            //从数据库得到题目
            int j = 0;
            String[] type = new String[]{"选择题","简答题","简答题"}; //题目类型
            String[] level = new String[]{"简单","一般","困难"}; //题目难度
            String[] text = new String[]{"转移后备缓冲器的英文缩写是 （    ）。",
                                         "转移后备缓冲器的英文缩写是 （    ）。",
                                         "转移后备缓冲器的英文缩写是 （    ）。"}; //问题
            String[] alphabet = new String[]{"A","B","C","D"}; //选项名，（A,B,C,D）
            String[] choiceText = new String[]{"CPU","MMU","PCB","TLB"}; //选项内容
            String[] matter = new String[]{"进程执行过程中任何时候都在在主存的部分被定义成成进程的常驻集。" ,
                    "在虚拟内存管理方案中，进程的驻留集一定的情况下，为了保证进程的局部性，操作系统需要依据某种策略将内存中的块置换出，" +
                    "如果被置换出的块正好在不不久将要被访问，而操作系统以又需要将其取回，频繁的这种操作将使处理器太部分时间都用于交换块，" +
                    "而不是执行指令，这种情况称之为系统抖动。"};

            //添加题目
            VBox question = new VBox();
            HBox hBox = new HBox();
            CheckBox check = new CheckBox();
            Label label = new Label((j+1)+". ["+ type[j]+"-"+level[j] +"]"+ text[j]);
            hBox.getChildren().addAll(check,label);
            question.getChildren().add(hBox);
            question.setMaxWidth(1200);

            //判断是否选择题
            if(type[j] == "选择题"){
                //添加选项
                for(int k = 0 ; k<4; k++){
                    Label choice =  new Label(alphabet[k]+". "+choiceText[k]);
                    choice.setPadding(new Insets(0,0,0,30));
                    question.getChildren().add(choice);
                }
            }
            else {
                Label questionText = new Label(matter[0]);
                question.getChildren().add(questionText);
            }

            //详细、修改、删除
            HBox hBox1 = new HBox(15);
            Button but1 = new Button("详细");
            Button but2 = new Button("修改");
            Button but3 = new Button("删除");
            //-fx-background-color: rgba(255, 255, 255, .7) 实现透明色
            but1.setStyle("-fx-text-fill: #666666; -fx-cursor: hand; -fx-background-color: rgba(255, 255, 255, .7)");
            but2.setStyle("-fx-text-fill: #0084ff; -fx-cursor: hand; -fx-background-color: rgba(255, 255, 255, .7)");
            but3.setStyle("-fx-text-fill: #fd4459; -fx-cursor: hand; -fx-background-color: rgba(255, 255, 255, .7)");
            hBox1.setPadding(new Insets(20,20,20,1000));
            hBox1.getChildren().addAll(but1,but2,but3);
            question.getChildren().add(hBox1);

            element.getChildren().add(question);
            box.getChildren().add(element);
        }
        box.setPadding(new Insets(30,30,30,30));
        return box;
    }

    //手动添加
    static Boolean cansee = true;
    public void ManuallyAdd(ActionEvent actionEvent) {
        //控制题库添加模块隐藏显示
        message.setVisible(!cansee);
        questions.setVisible(!cansee);
        add.setVisible(false);
        myImport.setVisible(false);

        message.setManaged(!cansee);
        questions.setManaged(!cansee);
        add.setManaged(false);
        myImport.setManaged(false);

        myAdd.setVisible(cansee);
        myAdd.setManaged(cansee);
        cansee=!cansee;

        question = true;
        visibility = true;
    }
    //选择题按钮
    public void ChoiceQuestion(ActionEvent actionEvent) {
        addEssayQuestion.setVisible(false);
        addCompletion.setVisible(false);
        addComprehensiveQuestion.setVisible(false);

        addEssayQuestion.setManaged(false);
        addCompletion.setManaged(false);
        addComprehensiveQuestion.setManaged(false);

        addChoiceQuestion.setVisible(true);
        addChoiceQuestion.setManaged(true);
    }
    //填空题按钮
    public void Completion(ActionEvent actionEvent) {
        addEssayQuestion.setVisible(false);
        addChoiceQuestion.setVisible(false);
        addComprehensiveQuestion.setVisible(false);

        addEssayQuestion.setManaged(false);
        addChoiceQuestion.setManaged(false);
        addComprehensiveQuestion.setManaged(false);

        addCompletion.setVisible(true);
        addCompletion.setManaged(true);
    }
    //问答题按钮
    public void EssayQuestion(ActionEvent actionEvent) {
        addChoiceQuestion.setVisible(false);
        addCompletion.setVisible(false);
        addComprehensiveQuestion.setVisible(false);

        addChoiceQuestion.setManaged(false);
        addCompletion.setManaged(false);
        addComprehensiveQuestion.setManaged(false);

        addEssayQuestion.setVisible(true);
        addEssayQuestion.setManaged(true);
    }
    //综合题按钮
    public void CompreQuetion(ActionEvent actionEvent) {
        addChoiceQuestion.setVisible(false);
        addCompletion.setVisible(false);
        addEssayQuestion.setVisible(false);

        addChoiceQuestion.setManaged(false);
        addCompletion.setManaged(false);
        addEssayQuestion.setManaged(false);

        addComprehensiveQuestion.setVisible(true);
        addComprehensiveQuestion.setManaged(true);
    }

    //文档导入
    static Boolean visibility = true;
    //文档导入模块隐藏显示
    public void ImportDocument(ActionEvent actionEvent) {

        message.setVisible(!visibility);
        questions.setVisible(!visibility);
        add.setVisible(false);
        myAdd.setVisible(false);

        message.setManaged(!visibility);
        questions.setManaged(!visibility);
        add.setManaged(false);
        myAdd.setManaged(false);


        //切换
        myImport.setVisible(visibility);
        myImport.setManaged(visibility);
        visibility = !visibility;

        question = true;
        cansee = true;
    }
    //下载Word模板
    public void DownLoad(ActionEvent actionEvent) {

    }
    //上传Word模板
    public void UpLoad(ActionEvent actionEvent) {

    }
    //取消文档导入
    public void CancelImport(ActionEvent actionEvent) {
    }

    //发布试卷按钮
    public void releasePaper(ActionEvent actionEvent) {

    }

    //修改分值
    public void correctScore(ActionEvent actionEvent) {
        new correctWindows().display("修改分值","修改题目所选分值为：");
    }
    //弹出窗口
    public class correctWindows{
        public void display(String title , String text){
            Stage window = new Stage();
            window.setTitle(title);
            //modality要使用Modality.APPLICATION_MODEL
            window.initModality(Modality.APPLICATION_MODAL);
            window.setMinWidth(300);
            window.setMinHeight(150);

            HBox button = new HBox();
            JFXButton button1 = new JFXButton("确定");
            JFXButton button2 = new JFXButton("取消");
            button2.setOnAction(e -> window.close());
            button.getChildren().addAll(button1,button2);

            HBox center = new HBox();
            Label label = new Label(text);
            TextField score = new TextField();
            center.getChildren().addAll(label,score);

            VBox layout = new VBox(10);
            layout.getChildren().addAll(center , button);
            layout.setAlignment(Pos.CENTER);

            Scene scene = new Scene(layout);
            window.setScene(scene);
            //使用showAndWait()先处理这个窗口
            window.showAndWait();
        }
    }

    //首页上下翻页按钮
    //选择题
    public void prePage1(ActionEvent actionEvent) {
        if(i == 1){
            prePage1.setDisable(true);
        }
        else{
            prePage1.setDisable(false);
        }
        if(i == choiceLength-1) {
            nextPage1.setDisable(false);
        }
        i--;
        ChoiceTestQuestions choiceQuestion = choiceQuestions.get(i);
        choiceNumber.setText(Integer.toString(i+1));
        choiceQuestionText.setText(choiceQuestion.getQuestionText());
        choiceScore.setText(choiceQuestion.getScore());
        aChoice.setText(choiceQuestion.getaChoice());
        bChoice.setText(choiceQuestion.getbChoice());
        cChoice.setText(choiceQuestion.getcChoice());
        dChoice.setText(choiceQuestion.getdChoice());
    }
    public void nextPage1(ActionEvent actionEvent) {
        if(i == choiceLength-2){
            nextPage1.setDisable(true);
        }
        else{
            nextPage1.setDisable(false);
        }
        if(i == 0) {
            prePage1.setDisable(false);
        }
        i++;
        ChoiceTestQuestions choiceQuestion = choiceQuestions.get(i);
        choiceNumber.setText(Integer.toString(i+1));
        choiceQuestionText.setText(choiceQuestion.getQuestionText());
        choiceScore.setText(choiceQuestion.getScore());
        aChoice.setText(choiceQuestion.getaChoice());
        bChoice.setText(choiceQuestion.getbChoice());
        cChoice.setText(choiceQuestion.getcChoice());
        dChoice.setText(choiceQuestion.getdChoice());
    }
    //判断题
    public void prePage2(ActionEvent actionEvent) {
        if(j == 6){
            prePage2.setDisable(true);
        }
        else{
            prePage2.setDisable(false);
        }
        if(j < judgeLength) {
            nextPage2.setDisable(false);
        }
        j -= 6;
        if(j<judgeLength){
            if(judge.getChildren().size() == 0){
                judge.getChildren().add(remove1);
                judge.getChildren().add(remove2);
            }
            JudgeTestQuestions judgeQuestion1 = judgeQuestions.get(j);
            judgeNumber1.setText(Integer.toString(j+1));
            judgeQuestionText1.setText(judgeQuestion1.getContent());
            judgeScore1.setText(judgeQuestion1.getScore());
        }
        if(j+1<judgeLength){
            if(judge.getChildren().size() == 2){
                judge.getChildren().add(remove3);
                judge.getChildren().add(remove4);
            }
            JudgeTestQuestions judgeQuestion2 = judgeQuestions.get(j+1);
            judgeNumber2.setText(Integer.toString(j+2));
            judgeQuestionText2.setText(judgeQuestion2.getContent());
            judgeScore2.setText(judgeQuestion2.getScore());
        }
        if(j+2<judgeLength){
            if(judge.getChildren().size() == 4){
                judge.getChildren().add(remove5);
                judge.getChildren().add(remove6);
            }
            JudgeTestQuestions judgeQuestion3 = judgeQuestions.get(j+2);
            judgeNumber3.setText(Integer.toString(j+3));
            judgeQuestionText3.setText(judgeQuestion3.getContent());
            judgeScore3.setText(judgeQuestion3.getScore());
        }
        if(j+3<judgeLength){
            if(judge.getChildren().size() == 6){
                judge.getChildren().add(remove7);
                judge.getChildren().add(remove8);
            }
            JudgeTestQuestions judgeQuestion4 = judgeQuestions.get(j+3);
            judgeNumber4.setText(Integer.toString(j+4));
            judgeQuestionText4.setText(judgeQuestion4.getContent());
            judgeScore4.setText(judgeQuestion4.getScore());
        }
        if(j+4<judgeLength){
            if(judge.getChildren().size() == 8){
                judge.getChildren().add(remove9);
                judge.getChildren().add(remove10);
            }
            JudgeTestQuestions judgeQuestion5 = judgeQuestions.get(j+4);
            judgeNumber5.setText(Integer.toString(j+5));
            judgeQuestionText5.setText(judgeQuestion5.getContent());
            judgeScore5.setText(judgeQuestion5.getScore());
        }
        if(j+5<judgeLength){
            if(judge.getChildren().size() == 10){
                judge.getChildren().add(remove11);
                judge.getChildren().add(remove12);
            }
            JudgeTestQuestions judgeQuestion6 = judgeQuestions.get(j+5);
            judgeNumber6.setText(Integer.toString(j+6));
            judgeQuestionText6.setText(judgeQuestion6.getContent());
            judgeScore6.setText(judgeQuestion6.getScore());
        }
    }
    public void nextPage2(ActionEvent actionEvent) {
        if(j >= judgeLength-12){
            nextPage2.setDisable(true);
        }
        else{
            nextPage2.setDisable(false);
        }
        if(j == 0) {
            prePage2.setDisable(false);
        }
        j += 6;
        if(j<judgeLength){
            JudgeTestQuestions judgeQuestion1 = judgeQuestions.get(j);
            judgeNumber1.setText(Integer.toString(j+1));
            judgeQuestionText1.setText(judgeQuestion1.getContent());
            judgeScore1.setText(judgeQuestion1.getScore());
        }
        else{
            judge.getChildren().remove(remove1);
            judge.getChildren().remove(remove2);
        }
        if(j+1<judgeLength){
            JudgeTestQuestions judgeQuestion2 = judgeQuestions.get(j+1);
            judgeNumber2.setText(Integer.toString(j+2));
            judgeQuestionText2.setText(judgeQuestion2.getContent());
            judgeScore2.setText(judgeQuestion2.getScore());
        }
        else{
            judge.getChildren().remove(remove3);
            judge.getChildren().remove(remove4);
        }
        if(j+2<judgeLength){
            JudgeTestQuestions judgeQuestion3 = judgeQuestions.get(j+2);
            judgeNumber3.setText(Integer.toString(j+3));
            judgeQuestionText3.setText(judgeQuestion3.getContent());
            judgeScore3.setText(judgeQuestion3.getScore());
        }
        else{
            judge.getChildren().remove(remove5);
            judge.getChildren().remove(remove6);
        }
        if(j+3<judgeLength){
            JudgeTestQuestions judgeQuestion4 = judgeQuestions.get(j+3);
            judgeNumber4.setText(Integer.toString(j+4));
            judgeQuestionText4.setText(judgeQuestion4.getContent());
            judgeScore4.setText(judgeQuestion4.getScore());
        }
        else{
            judge.getChildren().remove(remove7);
            judge.getChildren().remove(remove8);
        }
        if(j+4<judgeLength){
            JudgeTestQuestions judgeQuestion5 = judgeQuestions.get(j+4);
            judgeNumber5.setText(Integer.toString(j+5));
            judgeQuestionText5.setText(judgeQuestion5.getContent());
            judgeScore5.setText(judgeQuestion5.getScore());
        }
        else{
            judge.getChildren().remove(remove9);
            judge.getChildren().remove(remove10);
        }
        if(j+5<judgeLength){
            JudgeTestQuestions judgeQuestion6 = judgeQuestions.get(j+5);
            judgeNumber6.setText(Integer.toString(j+6));
            judgeQuestionText6.setText(judgeQuestion6.getContent());
            judgeScore6.setText(judgeQuestion6.getScore());
        }
        else{
            judge.getChildren().remove(remove11);
            judge.getChildren().remove(remove12);
        }
    }
    //填空题
    public void prePage3(ActionEvent actionEvent) {
        if(k == 5){
            prePage3.setDisable(true);
        }
        else{
            prePage3.setDisable(false);
        }
        if(k < gapLength) {
            nextPage3.setDisable(false);
        }
        k -= 5;
        if(k<gapLength){
            if(gap.getChildren().size() == 0){
                gap.getChildren().add(gapRemove1);
                gap.getChildren().add(gapRemove2);
            }
            GapTestQuestions gapQuestion1 = gapQuestions.get(k);
            gapNumber1.setText(Integer.toString(k+1));
            gapQuestionText1.setText(gapQuestion1.getContent());
            gapScore1.setText(gapQuestion1.getScore());
        }
        if(k+1<gapLength){
            if(gap.getChildren().size() == 2){
                gap.getChildren().add(gapRemove3);
                gap.getChildren().add(gapRemove4);
            }
            GapTestQuestions gapQuestion2 = gapQuestions.get(k+1);
            gapNumber2.setText(Integer.toString(k+2));
            gapQuestionText2.setText(gapQuestion2.getContent());
            gapScore2.setText(gapQuestion2.getScore());
        }
        if(k+2<gapLength){
            if(gap.getChildren().size() == 4){
                gap.getChildren().add(gapRemove5);
                gap.getChildren().add(gapRemove6);
            }
            GapTestQuestions gapQuestion3 = gapQuestions.get(k+2);
            gapNumber3.setText(Integer.toString(k+3));
            gapQuestionText3.setText(gapQuestion3.getContent());
            gapScore3.setText(gapQuestion3.getScore());
        }
        if(k+3<gapLength){
            if(gap.getChildren().size() == 6){
                gap.getChildren().add(gapRemove7);
                gap.getChildren().add(gapRemove8);
            }
            GapTestQuestions gapQuestion4 = gapQuestions.get(k+3);
            gapNumber4.setText(Integer.toString(k+4));
            gapQuestionText4.setText(gapQuestion4.getContent());
            gapScore4.setText(gapQuestion4.getScore());
        }
        if(k+4<gapLength){
            if(gap.getChildren().size() == 8){
                gap.getChildren().add(gapRemove9);
                gap.getChildren().add(gapRemove10);
            }
            GapTestQuestions gapQuestion5 = gapQuestions.get(k+4);
            gapNumber5.setText(Integer.toString(k+5));
            gapQuestionText5.setText(gapQuestion5.getContent());
            gapScore5.setText(gapQuestion5.getScore());
        }
    }
    public void nextPage3(ActionEvent actionEvent) {
        if(k >= gapLength-10){
            nextPage3.setDisable(true);
        }
        else{
            nextPage3.setDisable(false);
        }
        if(k == 0) {
            prePage3.setDisable(false);
        }
        k += 5;
        if(k<gapLength){
            GapTestQuestions gapQuestion1 = gapQuestions.get(k);
            gapNumber1.setText(Integer.toString(k+1));
            gapQuestionText1.setText(gapQuestion1.getContent());
            gapScore1.setText(gapQuestion1.getScore());
        }
        else{
            gap.getChildren().remove(gapRemove1);
            gap.getChildren().remove(gapRemove2);
        }
        if(k+1<gapLength){
            GapTestQuestions gapQuestion2 = gapQuestions.get(k+1);
            gapNumber2.setText(Integer.toString(k+2));
            gapQuestionText2.setText(gapQuestion2.getContent());
            gapScore2.setText(gapQuestion2.getScore());
        }
        else{
            gap.getChildren().remove(gapRemove3);
            gap.getChildren().remove(gapRemove4);
        }
        if(k+2<gapLength){
            GapTestQuestions gapQuestion3 = gapQuestions.get(k+2);
            gapNumber3.setText(Integer.toString(k+3));
            gapQuestionText3.setText(gapQuestion3.getContent());
            gapScore3.setText(gapQuestion3.getScore());
        }
        else{
            gap.getChildren().remove(gapRemove5);
            gap.getChildren().remove(gapRemove6);
        }
        if(k+3<gapLength){
            GapTestQuestions gapQuestion4 = gapQuestions.get(k+3);
            gapNumber4.setText(Integer.toString(k+4));
            gapQuestionText4.setText(gapQuestion4.getContent());
            gapScore4.setText(gapQuestion4.getScore());
        }
        else{
            gap.getChildren().remove(gapRemove7);
            gap.getChildren().remove(gapRemove8);
        }
        if(k+4<gapLength){
            GapTestQuestions gapQuestion5 = gapQuestions.get(k+4);
            gapNumber5.setText(Integer.toString(k+5));
            gapQuestionText5.setText(gapQuestion5.getContent());
            gapScore5.setText(gapQuestion5.getScore());
        }
        else{
            gap.getChildren().remove(gapRemove9);
            gap.getChildren().remove(gapRemove10);
        }
    }
    //简答题
    public void prePage4(ActionEvent actionEvent) {
        if(m == 1){
            prePage4.setDisable(true);
        }
        else{
            prePage4.setDisable(false);
        }
        if(m == essayLength-1) {
            nextPage4.setDisable(false);
        }
        m--;
        EssayTestQuestions essayQuestion = essayQuestions.get(m);
        essayNumber.setText(Integer.toString(m+1));
        essayQuestionText.setText(essayQuestion.getContent());
        essayScore.setText(essayQuestion.getScore());
    }
    public void nextPage4(ActionEvent actionEvent) {
        if(m == essayLength-2){
            nextPage4.setDisable(true);
        }
        else{
            nextPage4.setDisable(false);
        }
        if(m == 0) {
            prePage4.setDisable(false);
        }
        m++;
        EssayTestQuestions essayQuestion = essayQuestions.get(m);
        essayNumber.setText(Integer.toString(m+1));
        essayQuestionText.setText(essayQuestion.getContent());
        essayScore.setText(essayQuestion.getScore());
    }

    //多选框功能实现
    //选择题
    public void isCheck1(ActionEvent actionEvent) {
        if(check1.isSelected() == true){
            //选择题全选
            choiceCheck.setSelected(true);
        }
        else{
            //取消全选
            choiceCheck.setSelected(false);
        }
    }
    //判断题
    public void isCheck2(ActionEvent actionEvent) {
        if(check2.isSelected() == true){
            //判断题全选
            judgeCheck1.setSelected(true);
            judgeCheck2.setSelected(true);
            judgeCheck3.setSelected(true);
            judgeCheck4.setSelected(true);
            judgeCheck5.setSelected(true);
            judgeCheck6.setSelected(true);
        }
        else{
            judgeCheck1.setSelected(false);
            judgeCheck2.setSelected(false);
            judgeCheck3.setSelected(false);
            judgeCheck4.setSelected(false);
            judgeCheck5.setSelected(false);
            judgeCheck6.setSelected(false);
        }
    }
    //填空题
    public void isCheck3(ActionEvent actionEvent) {
        if(check3.isSelected() == true){
            //填空题全选
            gapCheck1.setSelected(true);
            gapCheck2.setSelected(true);
            gapCheck3.setSelected(true);
            gapCheck4.setSelected(true);
            gapCheck5.setSelected(true);
        }
        else{
            gapCheck1.setSelected(false);
            gapCheck2.setSelected(false);
            gapCheck3.setSelected(false);
            gapCheck4.setSelected(false);
            gapCheck5.setSelected(false);
        }
    }
    //简答题
    public void isCheck4(ActionEvent actionEvent) {
        if(check4.isSelected() == true){
            //简答题全选
            essayCheck.setSelected(true);
        }
        else{
            essayCheck.setSelected(false);
        }
    }

    //题目难易统计
    //选择题
    public int[] choiceLevel(List<ChoiceTestQuestions> choiceQuestions){
        int[] level = new int[3];
        for(int i = 0; i<choiceLength; i++){
            if(choiceQuestions.get(i).getLevel().equals("1"))
                level[0]++;
            else if(choiceQuestions.get(i).getLevel().equals("2"))
                level[1]++;
            else if(choiceQuestions.get(i).getLevel().equals("3"))
                level[2]++;
        }
        return level;
    }
    //判断题
    public int[] judgeLevel(List<JudgeTestQuestions> judgeQuestions) {
        int[] level = new int[3];
        for(int i = 0; i<judgeLength; i++){
            if(judgeQuestions.get(i).getLevel().equals("1"))
                level[0]++;
            else if(judgeQuestions.get(i).getLevel().equals("2"))
                level[1]++;
            else if(judgeQuestions.get(i).getLevel().equals("3"))
                level[2]++;
        }
        return level;
    }
    //填空题
    public int[] gapLevel(List<GapTestQuestions> gapQuestions) {
        int[] level = new int[3];
        for(int i = 0; i<gapLength; i++){
            if(gapQuestions.get(i).getLevel().equals("1"))
                level[0]++;
            else if(gapQuestions.get(i).getLevel().equals("2"))
                level[1]++;
            else if(gapQuestions.get(i).getLevel().equals("3"))
                level[2]++;
        }
        return level;
    }
    //简答题
    public int[] essayLevel(List<EssayTestQuestions> essayQuestions) {
        int[] level = new int[3];
        for(int i = 0; i<essayLength; i++){
            if(essayQuestions.get(i).getLevel().equals("1"))
                level[0]++;
            else if(essayQuestions.get(i).getLevel().equals("2"))
                level[1]++;
            else if(essayQuestions.get(i).getLevel().equals("3"))
                level[2]++;
        }
        return level;
    }

    //题目分数统计
    public int totalScore(List<ChoiceTestQuestions> choiceQuestions, List<JudgeTestQuestions> judgeQuestions,
                          List<GapTestQuestions> gapQuestions, List<EssayTestQuestions> essayQuestions){
        int score = 0;
        for(int i = 0; i<choiceLength; i++){
            score += Integer.parseInt(choiceQuestions.get(i).getScore());
        }
        for(int i = 0; i<judgeLength; i++){
            score += Integer.parseInt(judgeQuestions.get(i).getScore());
        }
        for(int i = 0; i<gapLength; i++){
            score += Integer.parseInt(gapQuestions.get(i).getScore());
        }
        for(int i = 0; i<essayLength; i++){
            score += Integer.parseInt(essayQuestions.get(i).getScore());
        }
        return score;
    }
}
